package login.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import login.entity.User;
import login.service.UserService;
import login.service.UserServiceimpl;

public class den extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserService userBiz=new UserServiceimpl();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user = userBiz.login(username, password);
		if(null!=user) {
		request.getSession().setAttribute("username", user.getUsername());
		response.sendRedirect("/jieyes2/hou/index.jsp");
		}else {
		response.sendRedirect("/jieyes2/hou/login.jsp");
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		doGet(request, response);	
	}

}
